import Vue from 'vue'
import Router from 'vue-router'
import {hasSubModules, hasLoadSubModules, loadSubModule} from './asyncRouter'
Vue.use(Router)
window.__POWER__ = true
const routes = [
  {
    path: '/',
    component: () => import('../pages/Page1')
  }
]

const router = new Router({
  routes
})
router.beforeEach((to, from, next) => {
  let modulekey = to.path.split('/')[1]
  if (hasSubModules(modulekey)) {
    if (!hasLoadSubModules(modulekey)) {
      loadSubModule(modulekey).then(() => {
        next({to, replace: true})
      })
    } else {
      next()
    }
  } else {
    next()
  }
})
export default router
